<?php
namespace Model;

use Model\Factory\TableGatewayFactory;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Predicate\Like;
use Zend\Db\Sql\Predicate\Operator;
use Zend\Db\Sql\Select;
use Zend\InputFilter\InputFilter;

class DishCategoryTable extends AbstractTable
{
    private $_lang;
    /**
     * @param $id
     * @return DishCategory
     */
    public function getDishCategory($id){
       return $this->getById($id);
    }



    /**
     * @return InputFilter
     */
    public function getInputFilter()
    {
        $filter = new InputFilter();


        return $filter;
    }

    public function getAllCategoryByDishId($id, $lang)
    {
        $categoryTable = TableGatewayFactory::getCategoryTable($lang);
        $select = $categoryTable->getDbSqlSelect();
        $select->join(array('dc'=>'dish_category'), 'dc.category_id = category.id', array())
            ->where(array('dc.dish_id'=>$id))
        ->where(array('lang'=>$lang));
        return $categoryTable-> executeSelectForArray($select);

    }

    public function getAllCategoryByDishIdAndGroup($id, $lang, $categoryGroup)
    {

        $categoryTable = TableGatewayFactory::getCategoryTable($lang);
        $rootCategory = $categoryTable->getRootCategory($categoryGroup);
        $select = $categoryTable->getDbSqlSelect();
        $select->join(array('dc'=>'dish_category'), 'dc.category_id = category.id', array())
            ->where(array('dc.dish_id'=>$id))
            ->where(array('lang'=>$lang))
        ->where('lft > '.$rootCategory->lft)
            ->where('rgt < '.$rootCategory->rgt)
        ->where(array('group_code'=>$categoryGroup));

        return $categoryTable-> executeSelectForArray($select);

    }





}